#include "widget.h"
#include "ui_widget.h"
#include <QLabel>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    QLabel* label = new QLabel(ui->tab);
    label->resize(200, 100);
    label->setText("这是一个label");
    QLabel* label2 = new QLabel(ui->tab_2);
    label2->setGeometry(0, 0, 200, 100);
    label2->setText("这是一段文本");
    ui->tabWidget->setTabsClosable(true);
    connect(ui->tabWidget, &QTabWidget::tabCloseRequested, this, &Widget::on_pushButton_2_clicked);
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_clicked()
{
    int count = ui->tabWidget->count();
    QWidget* cur = new QWidget();
    ui->tabWidget->addTab(cur, "Tab " + QString::number(count + 1));
    QLabel* label = new QLabel(cur);
    label->resize(200, 100);
    label->setText("这是一段文本");
    ui->tabWidget->setCurrentIndex(count);
}

void Widget::on_pushButton_2_clicked()
{
    ui->tabWidget->removeTab(ui->tabWidget->currentIndex());
}
